
Imports System
Imports System.Collections

Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for post_member_blog_comment.
	''' </summary>
	Public Partial Class post_member_blog_comment
		Inherits BaseWebPage
		Protected sLinkTag As String = Constants.BLOG_ADD_LINK_TAG
		Protected sImageTag As String = Constants.BLOG_ADD_IMAGE_TAG
		Protected btnAddImage As System.Web.UI.WebControls.Button
		Protected btnAddLink As System.Web.UI.WebControls.Button
		Private blogID As Integer = -1
		Private memberID As Integer = -1
		Protected htPageConstants As New Hashtable()
		Protected tblPostComment As System.Web.UI.HtmlControls.HtmlTable

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			' Put user code to initialize the page here
			' this.pageTemplate.PageTitle = PageTitles.POST_BLOG_COMMENT_PAGE;
			Dim usr As User = LoggedUser
			If usr = Nothing Then
				Common.Utils.RedirectToLoginPage(Page)
			End If

			If Request.Params("usr") = Nothing AndAlso Request.Params("usr") = "" Then
				Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
			End If

			' init page from XML
			Me.initPageTitles(Constants.POST_MEMBER_BLOG_COMMENT, "", Form1, Nothing, htPageConstants)
			Me.initAdvertisements(Form1, Nothing)

			blogID = Convert.ToInt32(Request.Params("id"))
			memberID = Convert.ToInt32(Request.Params("usr"))
			Dim member As User = Users.GetUserByID(memberID)

			If member <> Nothing AndAlso member.ID <> LoggedUser.ID Then
				ucMemberShortcut.UserID = member.ID
				trUserShortCut.Visible = True
			Else
				trUserShortCut.Visible = False
			End If

			If Not member.DirectFriends.Contains(LoggedUser.ID) Then
				Throw New Exception(Constants.ERROR_MESSAGE_NOT_FRIEND_BLOG_COMMENT)
			Else
				hlReturnToBlog.Text = (Me.GetPageConstText(htPageConstants, "CONST_Return_TEXT")).Replace("[PARAM]", member.Name)
				hlReturnToBlog.NavigateUrl = "../" + Constants.VIEW_MEMBER_BLOG + "?id=" + memberID

				txtMessage.Attributes.Add("onKeyDown", Constants.ON_KEY_DOWN_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_BLOG_MAX_CHARS.ToString()))
				txtMessage.Attributes.Add("onKeyUp", Constants.ON_KEY_UP_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_BLOG_MAX_CHARS.ToString()))
			End If
		End Sub

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()

		End Sub
#End Region

		Protected Sub btnPostBlogComment_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			'string subject = "";
			Dim body As String = ""

			'subject = txtSubject.Text.Trim();
			body = txtMessage.Text.Trim()

			'subject = subject.Substring(0, Math.Min(subject.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS));
			body = body.Substring(0, Math.Min(body.Length, Constants.TEXT_AREA_BLOG_MAX_CHARS))

			Dim member As User = Users.GetUserByID(memberID)
			Dim blogNew As Blog
			If member.ApproveBlogComments Then
				blogNew = New Blog(blogID, LoggedUser.ID, "", body, True)
			Else
				blogNew = New Blog(blogID, LoggedUser.ID, "", body, False)
			End If
			blogNew.Send()

			Response.Redirect(Constants.VIEW_MEMBER_BLOG + "?id=" + memberID)
		End Sub

	End Class
End Namespace






